package com.pb.infra.oth.util;

import lombok.extern.slf4j.Slf4j;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * properties文件通用类
 *
 * @Author:liudebao
 * @Date: 2019/9/27
 */
@Slf4j
public class PropertiesUtil {
    private PropertiesUtil() {
        throw new IllegalStateException("Utility class");
    }

    /**
     * 获取值
     *
     * @param filePath 文件路径
     * @param key      配置项
     * @return
     */
    public static String getValue(String filePath, String key) {
        String value = null;
        InputStream in=null;
        try {
            Properties properties = new Properties();
            in = PropertiesUtil.class.getClassLoader().getResourceAsStream(filePath);
            properties.load(in);
            value = properties.getProperty(key);
        } catch (IOException e) {
            log.error("读取配置文件发生异常，原因：{}", e.getMessage(), e);
        }finally {
            try {
                in.close();
            }catch (IOException e){
                e.printStackTrace();
            }
        }
        return value;
    }
}
